/*
 * The class of the file proposal to send
 */
package model;

/**
 * SentFileProposal is the association of a filename and the netname of the
 * sender that proposes it.
 *
 * @author gb
 */
public class SentFileProposal implements Comparable<SentFileProposal> {

    private String fileName;
    private String rmNetname;

    /**
     * Creates an object of type SentFileProposal with the fields set to the
     * parameters.
     *
     * @param fileName the name of the file received in the proposal.
     * @param rmNetname the net name of the sender
     */
    public SentFileProposal(String fileName, String rmNetname) {
        this.fileName = fileName;
        this.rmNetname = rmNetname;
    }

    /**
     * Gets the file name of this proposal
     *
     * @return the file name
     */
    public String getFileName() {
        return fileName;
    }

    /**
     * Gets the remote net name of this proposal
     *
     * @return the remote net name of the sender
     */
    public String getRmNetname() {
        return rmNetname;
    }

    /**
     * Creates a String that discribes the object
     *
     * @return the object as a String
     */
    public String toString() {
        return "[" + this.fileName + "," + rmNetname + "]";
    }

    /**
     * Compare this file proposal to the object and return whether this is the
     * same proposal or not.
     *
     * @param o the object to compare to
     * @return whether this SentFileProposal is equal to the object or not
     */
    public boolean equals(Object o) {
        if (o instanceof SentFileProposal) {
            SentFileProposal sfp2 = (SentFileProposal) o;
            if (this.fileName.equals(sfp2.fileName) && this.rmNetname.equals(sfp2.rmNetname)) {
                return true;
            } else {
                return false;
            }
        } else {
            return false;
        }
    }

    /**
     * Compare this file proposal to the SentFileProposal received and return
     * whether it is greater than, lower than or equal to the other proposal.
     *
     * @param o the object to compare to
     * @return whether this SentFileProposal is greater than, lower than or
     * equal to the other proposal.
     */
    @Override
    public int compareTo(SentFileProposal o) {
        //Comparing first on the fileName
        int comparaison = this.fileName.compareTo(o.fileName);
        //If equality then comparing on the rmNetname
        if (comparaison == 0) {
            comparaison = this.rmNetname.compareTo(o.rmNetname);
        }

        return comparaison;
    }
}
